package com.lingnuo.mapper;

import com.lingnuo.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * UserMapper - 类功能描述
 *
 * @author 程序员-Su_xiaoxiang
 * @date 2025/3/26 15:36
 */
@Mapper
public interface UserMapper {
    // 用户登录
    @Select("SELECT * FROM users WHERE username = #{username} AND password = #{password}")
    User login(User user);
    // 用户注册
    @Insert("INSERT INTO users (username, password, email,image_path) VALUES (#{username}, #{password}, #{email},#{imagePath})")
    int register(User user);

    //查询用户
    @Select ("SELECT * FROM users")
    List<User> getAllUsers();


    // 根据id查询用户
    @Select ("SELECT * FROM users WHERE id = #{id}")
    User getUserById(int id);

    // 更新用户
    int updateUser(User user);

    // 根据id删除用户
    @Delete("Delete FROM users WHERE id = #{id}")
    int deleteUser(int id);
    // 根据用户名查询用户数量
    @Select("SELECT COUNT(*) FROM users WHERE username = #{username}")
    int selectUserByUsername(String username);

    // 更新用户信息，包括图片路径
    @Update("UPDATE users SET image_path = #{imagePath} WHERE id = #{id}")
    int updateUserImagePath(User user);
}
